package com.fram.controller.admin;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.api.project.request.CategoryRequest;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.base.BaseAdminController;
import com.fram.service.admin.CategroyService;

/**
 * 
 * @作者：大晓刚 @时间 2020年5月19日 @dascription: ->
 */
@RestController
@RequestMapping("/admin/{version}/auth/category")
public class CategorysController extends BaseAdminController {

	private static Logger LOG = LoggerFactory.getLogger(CategorysController.class);

	@Autowired
	private CategroyService categroyService;

	// -后台，点击详情 展示的下拉。
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	private ResponseMsg FromCategory(@RequestBody CategoryRequest request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			if (request.getDistributorId() == null) {
				request.setDistributorId(getDistributorId());
			}
			msg.setData(categroyService.listFromCategory(request));
		} catch (ProException e) {
			LOG.error("-针对店铺 展示分类->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-针对店铺 展示分类--->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
